<?php
/***
*
* Class: DeliveryService //收货地址服务
* Author: Jason ZHENG
* Data: 2018-07-18
*
***/
namespace App\Service;

use App\Service\DataReturnService as DRS;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session; 
use App\Common\Base;

class DeliveryService
{
	/**
     * 获取省市区名称及地址拼接
     */
    public static function get_delivery($province,$city,$district) 
    {
        if(!$province || !$city || !$district)
            return DRS::returnError(20289,'地址信息不全');

        $arr['province'] = DB::table('address')->where(['ID'=>$province,'LevelType'=>1])->value('Name');
        $arr['city'] = DB::table('address')->where(['ID'=>$city,'LevelType'=>2])->value('Name');
        $arr['district'] = DB::table('address')->where(['ID'=>$district,'LevelType'=>3])->value('Name');
        return $arr;
    }

    /**
     * 验证收货地址是否存在
     */
    
    public static function check_delivery($ids,$user_id) 
    {
       $id = is_array($ids) ? $ids : explode(',', $ids); 
       $where = [
            'user_id' => $user_id,
            'state' => 0, // 没有删除
       ];
       $row_delivery = DB::table('delivery')->where($where)->whereIn('id',$id)->get()->toarray();
       if(!$row_delivery){
           return FALSE;
       }else{
           return TRUE;
       }
    }
}